/**
 * http函数专门发送请求
 * @param {} param0 
 * @returns 
 */
export default function http({ url, method = "GET", data } = {}) {
    return new Promise((resolve, reject) => {
        const baseURL = "http://127.0.0.1:3001"
        $.ajax({
            url: baseURL + url,
            method,
            headers: { Authorization: localStorage.token },
            dataType: "JSON",
            data,
            success(msg) {
                resolve(msg)
            },
            error(err) {
                console.log("请求失败", err);
                //前端统一处理后端异常
                if (err.status == 401) {
/*                     localStorage.removeItem("token")
                    localStorage.removeItem("userInfo")
                    window.location.assign("./login.html") */
                } else if (err.status == 500) {
                    //跳转到一个页面，服务器开小差
                }
                reject(err)
            }
        })
    })
}